package com.tjmc.company.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.enums.DeliveryRecordStatusEnum;
import com.tjmc.company.service.DeliveryRecordsService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;

import com.tjmc.recruit.common.security.annotation.Inner;
import com.tjmc.recruit.user.dto.ResumeSearchDTO;
import com.tjmc.company.api.entity.DeliveryRecordsEntity;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 投递记录表
 *
 * @author recruit
 * @date 2024-11-14 16:56:22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/deliveryRecords")
@Tag(description = "deliveryRecords", name = "投递记录表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DeliveryRecordsController {

    private final DeliveryRecordsService deliveryRecordsService;

    /**
     * 分页查询
     *
     * @param page      分页对象
     * @param searchDTO 查询参数
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R getDeliveryRecordsPage(@ParameterObject Page page, @ParameterObject ResumeSearchDTO searchDTO) {
        return R.ok(deliveryRecordsService.getResumeDeliveryPage(page, searchDTO));
    }


    /**
     * 通过条件查询投递记录表
     *
     * @param deliveryRecords 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询", description = "通过条件查询对象")
    @GetMapping("/details")
    public R getDetails(@ParameterObject DeliveryRecordsEntity deliveryRecords) {
        return R.ok(deliveryRecordsService.list(Wrappers.query(deliveryRecords)));
    }

    /**
     * 新增投递记录表
     *
     * @param deliveryRecords 投递记录表
     * @return R
     */
    @Operation(summary = "新增投递记录表", description = "新增投递记录表")
    @SysLog("新增投递记录表")
    @PostMapping
    public R save(@RequestBody DeliveryRecordsEntity deliveryRecords) {
        deliveryRecords.setDeliveryStatus(DeliveryRecordStatusEnum.UNCHECK);
        deliveryRecords.setDeliveryStatusDesc(DeliveryRecordStatusEnum.UNCHECK.getDesc());
        return R.ok(deliveryRecordsService.save(deliveryRecords));
    }


    @Operation(summary = "修改投递记录状态", description = "修改投递记录状态")
    @SysLog("修改投递记录状态")
    @PutMapping("/updateStatus/{id}")
    public R updateStatus(@PathVariable Long id) {
        DeliveryRecordsEntity records = deliveryRecordsService.getById(id);
        if (records == null) {
            return R.failed("记录不存在");
        }
        records.setDeliveryStatus(DeliveryRecordStatusEnum.CHECK);
        records.setDeliveryStatusDesc(DeliveryRecordStatusEnum.CHECK.getDesc());
        return R.ok(deliveryRecordsService.updateById(records));
    }

    @Operation(summary = "修改投递记录", description = "修改投递记录")
    @SysLog("修改投递记录")
    @PutMapping("/update")
    public R update(@RequestBody DeliveryRecordsEntity deliveryRecords) {
        return R.ok(deliveryRecordsService.updateById(deliveryRecords));
    }


    /**
     * 通过id删除投递记录表
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除投递记录表", description = "通过id删除投递记录表")
    @SysLog("通过id删除投递记录表")
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(deliveryRecordsService.removeBatchByIds(CollUtil.toList(ids)));
    }
}
